package com.jservice.web.authc;

import com.jservice.framework.spring.SpringContextUtil;
import com.jservice.framework.utils.EncryptUtils;
import com.jservice.model.SysUser;
import org.springframework.stereotype.Service;

/**
 * LoginService
 *
 * @Author cwledit
 * @DATE 2017/5/30.
 */
@Service("authcService")
public class AuthcService {

    public static final SysUser UserDao = new SysUser();


    public static AuthcService me() {
        return SpringContextUtil.getBean("authcService");
    }

    /**
     * 验证用户名、密码（web 登录）
     * @param loginName
     * @param password
     * @return
     */
    public String valid(String loginName, String password){
        SysUser user = UserDao.getByLoginName(loginName);
        if (!((EncryptUtils.encryptPassword(password,user.getLoginName().substring(0,3))).equals(user.getPassword()))){
            return "用户名或密码错误";
        }
        if (user.getIsLocked()){
            return "用户被锁定";
        }
        if (!(user.getIsEnabled())){
            return "用户未启用";
        }
        return "success";
    }



}
